import QtQuick 1.0
import "Components/"

Rectangle {
    id: _root
    width: 300
    gradient: Gradient {
        GradientStop {
            position: 0
            color: "#0320ff"
        }

        GradientStop {
            position: 1
            color: "#000000"
        }
    }
    border.color: "#000000"
    height: buttonHeight//_title.height + 20

    property string appState: "Home"
    property bool loading: false

    property real density: 1.0
    property real buttonWidth: 33 * density
    property real buttonHeight: 33 * density

    ImageButton {
        id: _home
        width: buttonWidth
        height: buttonHeight
        anchors.leftMargin: 5
        anchors.left:  parent.left
        anchors.verticalCenter: parent.verticalCenter

        imageIdle: "../images/btn_home_i.png"
        imagePress: "../images/btn_home_p.png"

        onClicked: {
            _rootContainer.getActiveLine().content.state = "";

        }
    }

//    Text {
//        id: _title
//        color: "#ffffff"
//        text: "Rewit"
//        font.pixelSize: 14
//        anchors.leftMargin: 5
//        anchors.left:  parent.left
//        anchors.verticalCenter: parent.verticalCenter
//        smooth: true

//    }

    Text {
        id: _state
        color: "#ffffff"
        text: "-" + appState + "-"
        anchors.left: _home.right
        anchors.leftMargin: 5
        font.pixelSize: 14 * density
        anchors.verticalCenter: parent.verticalCenter
        smooth: true
    }

    ImageButton {
        id: _update
        width: buttonWidth
        height: buttonHeight
        anchors.rightMargin: 5
        anchors.right: _search.left
        anchors.verticalCenter: parent.verticalCenter

        imageIdle: "../images/btn_update_i.png"
        imagePress: "../images/btn_update_p.png"

//        //回転させる
//        NumberAnimation on rotation {
//            from: 0
//            to: 360
//            duration: 1500
//            loops: Animation.Infinite
//            running: _root.loading
//        }

        onClicked: {
            _rootContainer.getActiveLine().content.update();
        }
    }

    ImageButton {
        id: _search
        width: buttonWidth
        height: buttonHeight
        anchors.rightMargin: 5
        anchors.right: _tweet.left
        anchors.verticalCenter: parent.verticalCenter

        imageIdle: "../images/btn_search_i.png"
        imagePress: "../images/btn_search_p.png"

        onClicked: {
            // ツイートコンテナの開閉をトグル
            _rootContainer.openSearchContainer(!_rootContainer.isOpenSearchContainer());
        }
    }

    ImageButton {
        id: _tweet
        width: buttonWidth
        height: buttonHeight
        anchors.rightMargin: 5
        anchors.right: _menu.left
        anchors.verticalCenter: parent.verticalCenter

        imageIdle: "../images/btn_tweet_i.png"
        imagePress: "../images/btn_tweet_p.png"

        onClicked: {
            // ツイートコンテナの開閉をトグル
            _rootContainer.openTweetContainer(!_rootContainer.isOpenTweetContainer());
        }
    }

    ImageButton {
        id: _menu
        width: buttonWidth
        height: buttonHeight
        anchors.rightMargin: 5
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter

        onClicked: {
            if(_menuContainer.state !== "Menu"){
                _menuContainer.open("Menu");
            }
        }
    }


    MouseArea {
        anchors.top: parent.top
        anchors.left: _home.right
        anchors.bottom: parent.bottom
        anchors.right: _update.left

        onClicked: {
            _rootContainer.getActiveLine().content.state = "";
        }
    }
}
